import java.util.Arrays;

/**
 * @author cc
 */
public class LeetCode2352 {
    public static void main(String[] args) {
        System.out.println(equalPairs(new int[][]{{3,2,1},{1,7,6},{2,7,7}}));
    }

    /**
     * 思路
     * 1.取一个二维数组，和每个二维数组的第i个数组组合进行匹配，匹配成功，则+1
     * @param grid
     * @return
     */
    public static int equalPairs(int[][] grid) {
        int length = grid.length;
        int num = 0;
        for (int r = 0; r < length; r++){
            int[] row = grid[r];

            for (int x = 0;  x< length; x++){
                int[] colunm = new int[length];
                for (int y = 0; y < length; y++){
                    colunm[y] = grid[y][x];
                }

                if(Arrays.equals(row, colunm)){
                    num++;
                }

            }
        }

        return num;
    }


}
